"""
Case Type   : tools
Case Name   : 指定-?参数执行pg_resetxlog命令，显示帮助信息是否成功（数据库可以为运行状态）
Create At   : 2021/1/28
Owner       : opentestcase003
Description :
    1.使用-?参数执行pg_resetxlog
    pg_resetxlog -?
    2.信息是否查询成功
Expect      :
    1.使用-？参数执行pg_resetxlog成功
    2.信息查询成功
History     :
           modified by opentestcase012 2022/12/27 代码变更修改help断言
"""
import os
import unittest
from yat.test import Node
from yat.test import macro
from testcase.utils.Logger import Logger


class Tools(unittest.TestCase):
    def setUp(self):
        self.logger = Logger()
        self.logger.info(f'-----{os.path.basename(__file__)} start-----')
        self.userNode = Node('PrimaryDbUser')
        self.DB_ENV_PATH = macro.DB_ENV_PATH

    def test_systools(self):
        self.logger.info('--------查看帮助信息--------')
        help_msg = ['-e XIDEPOCH      set next transaction ID epoch',
                    '-f               force update to be done',
                    '-l xlogfile      force minimum WAL starting location for',
                    '-m XID           set next multitransaction ID',
                    '-n               no update, just show extracted control',
                    '-o OID           set next OID',
                    '-O OFFSET        set next multitransaction offset',
                    '-V, --version    output version information, then exit',
                    '-x XID           set next transaction ID',
                    '-?, --help       show this help, then exit',
                    '--vgname', 'the dss data on dss mode',
                    '--enable-dss     enable shared storage mode',
                    '--socketpath=SOCKETPATH', 'dss connect socket file path']
        excute_cmd1 = f'source {self.DB_ENV_PATH};pg_resetxlog -?'
        self.logger.info(excute_cmd1)
        msg1 = self.userNode.sh(excute_cmd1).result()
        self.logger.info(msg1)
        for content in (help_msg):
            self.logger.info(content)
            self.assertTrue(msg1.find(content) > -1)
        excute_cmd2 = f'source {self.DB_ENV_PATH};pg_resetxlog --help'
        self.logger.info(excute_cmd2)
        msg2 = self.userNode.sh(excute_cmd2).result()
        self.logger.info(msg2)
        for content in (help_msg):
            self.logger.info(content)
            self.assertTrue(msg1.find(content) > -1)

    def tearDown(self):
        self.logger.info(f'-----{os.path.basename(__file__)} end-----')
